//
//  LXPlatePlanTableViewCell.m
//  ZuLinProject
//
//  Created by bancheng on 2022/9/14.
//  Copyright © 2022 LX_App. All rights reserved.
//

#import "LXPlatePlanTableViewCell.h"
#import "LXPlateModel.h"
@interface LXPlatePlanTableViewCell ()
@property (nonatomic)NSMutableArray *data;

@end


@implementation LXPlatePlanTableViewCell


int plateHeight = 40;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier andShowWithData:(NSMutableArray *)data{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.data = data;

        
        
        [self.contentView addSubview:self.titleLab];
        
                
        NSArray *ary = @[@"类型",@"应付日期",@"金额",@"备注",@"状态"];
        
        CGFloat topX = 0;
        
        UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(15, self.titleLab.Y_height + 10, ScreenWidth - 30 , plateHeight)];
        topView.backgroundColor = ColorWithF5F5F5;
        [self.contentView addSubview:topView];
        for (int i = 0; i < ary.count; i++) {
    
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(topX, 0, topView.width/ary.count, topView.height)];
            label.textColor = ColorWith333333;
            label.font = [UIFont systemFontOfSize:15];
            label.textAlignment = NSTextAlignmentCenter;
            label.text = ary[i];
            [topView addSubview:label];
            
            topX = label.X_width;
        }
        
        
        CGFloat X = 15;
        CGFloat Y = topView.Y_height;
        CGFloat W = topView.width/ary.count;
                
        
        for (int i = 0; i < data.count; i++) {
            
            LXPlateModel *model = data[i];
            
            
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(X, Y, topView.width , plateHeight)];
            [self.contentView addSubview:view];
            [view addLeftBorderWithColor:[UIColor colorWithHexString:@"#F2F2F2"] andWidth:1];
            [view addRightBorderWithColor:[UIColor colorWithHexString:@"#F2F2F2"] andWidth:1];
            [view addBottomBorderWithColor:[UIColor colorWithHexString:@"#F2F2F2"] andWidth:1];

            
    
            UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, W, view.height)];
            label1.textColor = ColorWith666666;
            label1.numberOfLines = 2;
            label1.textAlignment = NSTextAlignmentCenter;
            label1.font = [UIFont systemFontOfSize:13];
            [view addSubview:label1];
            label1.text = @"牌照费";
            
            
            UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(label1.X_width, 0, W, view.height)];
            label2.textColor = ColorWith666666;
            label2.font = Fond12;
            label2.numberOfLines = 2;
            label2.textAlignment = NSTextAlignmentCenter;
            label2.text = model.exceptPaidDate;
            [view addSubview:label2];
            
            UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(label2.X_width, 0, W, view.height)];
            label3.textColor = ColorWith666666;
            label3.font = Fond13;
            label3.numberOfLines = 2;
            label3.adjustsFontSizeToFitWidth = YES;
            label3.textAlignment = NSTextAlignmentCenter;
            label3.text = model.amount;
            [view addSubview:label3];
            
            UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(label3.X_width, 0, W, view.height)];
            label4.textColor = ColorWith666666;
            label4.font = Fond13;
            label3.adjustsFontSizeToFitWidth = YES;
            label4.textAlignment = NSTextAlignmentCenter;
            label4.numberOfLines = 2;
            label4.text = model.remark;
            [view addSubview:label4];
            
            
            
            UILabel *label5 = [[UILabel alloc] initWithFrame:CGRectMake(label4.X_width, 0, W, view.height)];
            label5.textColor = ColorWith666666;
            label5.font = [UIFont systemFontOfSize:13];
            label5.textAlignment = NSTextAlignmentCenter;
            label5.numberOfLines = 2;
            
            if (model.settleState == 1) {
                label5.textColor = ColorWith3C6CFC;
                label5.text = [NSString stringWithFormat:@"已支付\n%@",model.paidDate];
                [label5 addAttributes:TextAttrCorlor(ColorWith3C6CFC) forText:model.paidDate size:[UIFont systemFontOfSize:10]];
            }
            else {
                label5.text = @"未支付";
                label5.textColor = ColorWithEA545A;
            }
            
            [view addSubview:label5];
           

            Y = view.Y_height;
        }

       
    }
    return self;
    
    
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier WithData:(nonnull NSMutableArray *)data{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.data = data;

        
        
        [self.contentView addSubview:self.titleLab];
        
                
        NSArray *ary = @[@"类型",@"应付日期",@"金额",@"备注",@"操作"];
        
        CGFloat topX = 0;
        
        UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(15, self.titleLab.Y_height + 10, ScreenWidth - 30 , plateHeight)];
        topView.backgroundColor = ColorWithF5F5F5;
        [self.contentView addSubview:topView];
        for (int i = 0; i < ary.count; i++) {
    
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(topX, 0, topView.width/ary.count, topView.height)];
            label.textColor = ColorWith333333;
            label.font = [UIFont systemFontOfSize:15];
            label.textAlignment = NSTextAlignmentCenter;
            label.text = ary[i];
            [topView addSubview:label];
            
            topX = label.X_width;
        }
        
        
        CGFloat X = 15;
        CGFloat Y = topView.Y_height;
        CGFloat W = topView.width/ary.count;
                
        BOOL isNull = NO;
        
        if (data.count == 0) {
            isNull = YES;
            NSArray *ary = @[
                
                @{
                    @"exceptPaidDate":@"--",
                    @"amount":@"--",
                    @"remark":@"--",
                    @"fundType":@"9",
                },
                
            ];
            data = [LXPlateModel mj_objectArrayWithKeyValuesArray:ary];
        }
        
        
        for (int i = 0; i < data.count; i++) {
            
            LXPlateModel *model = data[i];
            
            
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(X, Y, topView.width , plateHeight)];
            [self.contentView addSubview:view];
            [view addLeftBorderWithColor:[UIColor colorWithHexString:@"#F2F2F2"] andWidth:1];
            [view addRightBorderWithColor:[UIColor colorWithHexString:@"#F2F2F2"] andWidth:1];
            [view addBottomBorderWithColor:[UIColor colorWithHexString:@"#F2F2F2"] andWidth:1];

            
    
            UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, W, view.height)];
            label1.textColor = ColorWith666666;
            label1.numberOfLines = 2;
            label1.textAlignment = NSTextAlignmentCenter;
            label1.font = Fond13;
            [view addSubview:label1];
            label1.text = @"牌照费";
            
            
            UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(label1.X_width, 0, W, view.height)];
            label2.textColor = ColorWith666666;
            label2.font = Fond12;
            label2.numberOfLines = 2;
            label2.textAlignment = NSTextAlignmentCenter;
            label2.text = model.exceptPaidDate;
            [view addSubview:label2];
            
            UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(label2.X_width, 0, W, view.height)];
            label3.textColor = ColorWith666666;
            label3.font = Fond13;
            label3.numberOfLines = 2;
            label3.textAlignment = NSTextAlignmentCenter;
            label3.text = model.amount;
            [view addSubview:label3];
            
            UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(label3.X_width, 0, W, view.height)];
            label4.textColor = ColorWith666666;
            label4.font = Fond13;
            label4.textAlignment = NSTextAlignmentCenter;
            label4.numberOfLines = 2;
            label4.text = model.remark;
            [view addSubview:label4];
            
            UIButton *label5 = [[UIButton alloc] initWithFrame:CGRectMake(label4.X_width, 0, W, view.height)];
            label5.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            if (isNull) {
                [label5 setImage:[UIImage imageNamed:@"car_information_edit_ash"] forState:UIControlStateNormal];
            }
            else {
                [label5 setImage:[UIImage imageNamed:@"carDetail_修改信息"] forState:UIControlStateNormal];
                [label5 whenTapped:^{
                                    
                    if (self.clickBtnAction) {
                        self.clickBtnAction(model);
                    }
                }];
            }
            
            [view addSubview:label5];

            Y = view.Y_height;
        }

       
    }
    return self;
    
    
    
}
- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 18, 200, 18)];
        _titleLab.textColor = ColorWith333333;
        _titleLab.font = Fond16;
    }
    return _titleLab;
}
+ (CGFloat)getHeight:(NSArray *)ary{
    if (ary.count == 0) {
        return 145;
    }
    else {
        return ary.count * plateHeight + 65 + plateHeight;
    }
}
@end
